#include <cstring>
#include <iostream>

using namespace std;
const int N = 200 + 10;
int n, m, k;
int g[N][N];
int main() {
  cin >> n >> m >> k;
  memset(g, 0x3f, sizeof g);
  for (int i = 0; i <= n; ++i) {
    g[i][i] = 0;
  }
  while (m--) {
    int x, y, z;
    cin >> x >> y >> z;
    g[x][y] = min(g[x][y], z);
  }
  /** floyd */
  for (int k = 1; k <= n; ++k)
    for (int i = 1; i <= n; ++i)
      for (int j = 1; j <= n; ++j)
        if (g[i][j] > g[i][k] + g[k][j]) g[i][j] = g[i][k] + g[k][j];

  while (k--) {
    int x, y;
    cin >> x >> y;
    if (g[x][y] >= 0x3f3f3f3f / 2)
      cout << "impossible\n";
    else
      cout << g[x][y] << '\n';
  }
}